package com.briup.estore.web.servlet;

import com.briup.estore.common.result.Result;
import com.briup.estore.common.dto.UserLoginDto;
import com.briup.estore.common.utils.JsonUtils;
import com.briup.estore.service.UserService;
import com.briup.estore.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author briup-adam
 * @Date 2023/8/3 上午9:43
 * @Description  用户登录
 **/

@WebServlet("/user/login")
public class UserLoginServlet extends BaseServlet {
    private UserService userService = new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String data = readData(req);
        UserLoginDto dto = JsonUtils.toObject(data, UserLoginDto.class);
        String jwt = userService.login(dto);
        Result<String> result = Result.success(jwt);
        writeData(resp, result);

    }
}
